import { reqC1List, reqC2List, reqC3List } from "@/api/product/attr/attr";
import { defineStore } from 'pinia';
import type { categoryResponseData } from '@/api/product/attr/model/attr'


let useCategoryStore = defineStore('category', {
    //存储数据
    state: (): categoryStoreStateType => ({
        //存储一级分类的数据
        c1List: [],
        //存储二级分类的数据
        c2List: [],
        //存储三级分类的数据
        c3List: [],
        //收集一级分类的ID
        c1Id: '',
        //收集二级分类的ID
        c2Id: '',
        //收集三级分类的ID
        c3Id: '',
    }),

    //发送请求 处理业务
    actions: {
        //获取一级分类列表
        async getC1List() {
            let result = await reqC1List();
            this.c1List = result
        },
        //获取二级分类列表
        async getC2List() {
            //清空二级、三级分类ID->决定select显示内容
            this.c2Id = '';
            this.c3Id = '';
            //清空二级、三级分类options显示内容
            this.c2List = [];
            this.c3List = [];
            let result = await reqC2List(this.c1Id);
            this.c2List = result;
        },
        //获取三级分类列表
        async getC3List() {
           //清空三级分类ID->决定select显示内容
           this.c3Id = '';
           //清空三级分类options显示内容
           this.c3List = [];
           let result = await reqC3List(this.c2Id);
           this.c3List = result;
        }
    }
});

//对外暴露仓库
export default useCategoryStore;